import 'package:flutter/material.dart';

import './tabs/CategoryPage.dart';
import './tabs/HomePage.dart';
import './tabs/SettingPage.dart';
import './widget/DrawerDemo.dart';

class Tabs extends StatefulWidget {
  int currentIndex;

  Tabs({Key key, this.currentIndex: 0}) : super(key: key);
  @override
  _TabsState createState() => _TabsState(this.currentIndex);
}

class _TabsState extends State<Tabs> {
  int currentIndex = 0;
  _TabsState(this.currentIndex);
  List tabs = [
    {'body': HomePage(), 'title': '首页', 'icon': Icon(Icons.home)},
    {'body': CategoryPage(), 'title': '分页', 'icon': Icon(Icons.category)},
    {'body': SettingPage(), 'title': '设置', 'icon': Icon(Icons.settings)},
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          this.tabs[this.currentIndex]['title'],
          style: TextStyle(fontSize: 20.0),
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
          items: this
              .tabs
              .map((e) => BottomNavigationBarItem(
                  // ignore: deprecated_member_use
                  icon: e['icon'],
                  title: Text(e['title'])))
              .toList(),
          type: BottomNavigationBarType.fixed,
          currentIndex: this.currentIndex,
          // currentIndex: 0,
          onTap: (index) {
            setState(() {
              this.currentIndex = index;
            });
          },
          iconSize: 30,
          // backgroundColor: Colors.black,
          // fixedColor: Color.fromRGBO(204, 102, 51, .8),
          elevation: 0.0),
      body: this.tabs[this.currentIndex]['body'],
      drawer: DrawerDemo(),
    );
  }
}
